411b2c1ehdEGO_CwG0tvn85Q-Tfh5g tools/python/xen/xm/migrate.py
40cf2937PSslwBliN1g7ofDy2H_RhA tools/python/xen/xm/opts.py
40cf2937Z8WCNOnO2FcWdubvEAF9QQ tools/python/xen/xm/shutdown.py
+41b88ba6_C4---jeA895Efg9YFZgKA tools/python/xen/xm/sysrq.py
40fcefb2K1xqVVT4D-p7nL2GzS4scg tools/sv/Main.rpy
40ffbcb66Dj5F-1kCK9BcgSqCWkt1w tools/sv/Makefile
4120b0e5L_nW-u0MWRfIdXg4ng4OjA tools/sv/images/destroy.png
#include <linux/unistd.h>
#include <linux/module.h>
#include <linux/reboot.h>
+#include <linux/sysrq.h>
#include <asm/irq.h>
#include <asm/mmu_context.h>
#include <asm-xen/ctrl_if.h>
* Stop/pickle callback handling.
*/
-//#include <asm/suspend.h>
-
/* Ignore multiple shutdown requests. */
static int shutting_down = -1;
+static int pending_sysrq = -1;
static void __do_suspend(void)
{
}
}
+static void __sysrq_handler(void *unused)
+{
+#ifdef CONFIG_MAGIC_SYSRQ
+ handle_sysrq(pending_sysrq, NULL, NULL);
+#endif
+ pending_sysrq = -1;
+}
+
static void shutdown_handler(ctrl_msg_t *msg, unsigned long id)
{
static DECLARE_WORK(shutdown_work, __shutdown_handler, NULL);
+ static DECLARE_WORK(sysrq_work, __sysrq_handler, NULL);
if ( (shutting_down == -1) &&
((msg->subtype == CMSG_SHUTDOWN_POWEROFF) ||
shutting_down = msg->subtype;
schedule_work(&shutdown_work);
}
+ else if ( (pending_sysrq == -1) &&
+ (msg->subtype == CMSG_SHUTDOWN_SYSRQ) )
+ {
+ pending_sysrq = msg->msg[0];
+ schedule_work(&sysrq_work);
+ }
else
{
printk("Ignore spurious shutdown request\n");
return self.xendPost(self.domainurl(id),
{'op' : 'pause' })
- def xend_domain_shutdown(self, id, reason):
+ def xend_domain_shutdown(self, id, reason, key=None):
return self.xendPost(self.domainurl(id),
{'op' : 'shutdown',
- 'reason' : reason })
+ 'reason' : reason,
+ 'key' : key })
def xend_domain_destroy(self, id, reason):
return self.xendPost(self.domainurl(id),
except Exception, ex:
raise XendError(str(ex))
- def domain_shutdown(self, id, reason='poweroff'):
+ def domain_shutdown(self, id, reason='poweroff', key=None):
"""Shutdown domain (nicely).
- poweroff: restart according to exit code and restart mode
- reboot: restart on exit
eserver.inject('xend.domain.shutdown', [dominfo.name, dominfo.id, reason])
if reason == 'halt':
reason = 'poweroff'
- val = xend.domain_shutdown(dominfo.id, reason)
+ val = xend.domain_shutdown(dominfo.id, reason, key)
self.refresh_schedule()
return val
raise XendError('Invalid console id')
console.disconnect()
- def domain_shutdown(self, dom, reason):
+ def domain_shutdown(self, dom, reason, key=None):
"""Shutdown a domain.
"""
dom = int(dom)
ctrl = self.domainCF.getController(dom)
if not ctrl:
raise XendError('No domain controller: %s' % dom)
- ctrl.shutdown(reason)
+ ctrl.shutdown(reason, key)
return 0
def domain_mem_target_set(self, dom, target):
def op_shutdown(self, op, req):
fn = FormFn(self.xd.domain_shutdown,
[['dom', 'str'],
- ['reason', 'str']])
+ ['reason', 'str'],
+ ['key', 'int']])
val = fn(req.args, {'dom': self.dom.id})
req.setResponseCode(http.ACCEPTED)
req.setHeader("Location", "%s/.." % req.prePathURL())
"""
reasons = {'poweroff' : 'shutdown_poweroff_t',
'reboot' : 'shutdown_reboot_t',
- 'suspend' : 'shutdown_suspend_t' }
+ 'suspend' : 'shutdown_suspend_t',
+ 'sysrq' : 'shutdown_sysrq_t' }
def __init__(self, factory, dom):
controller.Controller.__init__(self, factory, dom)
self.addMethod(CMSG_MEM_REQUEST, 0, None)
self.registerChannel()
- def shutdown(self, reason):
+ def shutdown(self, reason, key=None):
"""Shutdown a domain.
reason shutdown reason
+ key sysrq key (only if reason is 'sysrq')
"""
msgtype = self.reasons.get(reason)
if not msgtype:
raise XendError('invalid reason:' + reason)
- msg = packMsg(msgtype, {})
- self.writeRequest(msg)
+ extra = {}
+ if reason == 'sysrq': extra['key'] = key
+ print extra
+ self.writeRequest(packMsg(msgtype, extra))
def mem_target_set(self, target):
"""Set domain memory target in pages.
CMSG_SHUTDOWN_POWEROFF = 0
CMSG_SHUTDOWN_REBOOT = 1
CMSG_SHUTDOWN_SUSPEND = 2
+CMSG_SHUTDOWN_SYSRQ = 3
STOPCODE_shutdown = 0
STOPCODE_reboot = 1
STOPCODE_suspend = 2
+STOPCODE_sysrq = 3
shutdown_formats = {
'shutdown_poweroff_t':
'shutdown_suspend_t':
(CMSG_SHUTDOWN, CMSG_SHUTDOWN_SUSPEND),
+
+ 'shutdown_sysrq_t':
+ (CMSG_SHUTDOWN, CMSG_SHUTDOWN_SYSRQ)
}
msg_formats.update(shutdown_formats)
from xen.xend import sxp
from xen.xend.XendClient import XendError, server
from xen.xend.XendClient import main as xend_client_main
-from xen.xm import create, destroy, migrate, shutdown
+from xen.xm import create, destroy, migrate, shutdown, sysrq
from xen.xm.opts import *
class Group:
xm.prog(ProgShutdown)
+class ProgSysrq(Prog):
+ group = 'domain'
+ name = "sysrq"
+ info = """Send a sysrq to a domain."""
+
+ def help(self, args):
+ sysrq.main([args[0], '-h'])
+
+ def main(self, args):
+ sysrq.main(args)
+
+xm.prog(ProgSysrq)
+
class ProgPause(Prog):
group = 'domain'
name = "pause"
--- /dev/null
+# (C) Matthew Bloch <matthew@bytemark.co.uk> 2004
+
+"""Domain shutdown.
+"""
+import string
+import sys
+import time
+
+from xen.xend.XendClient import server
+from xen.xm.opts import *
+
+DOM0_NAME = 'Domain-0'
+DOM0_ID = '0'
+
+gopts = Opts(use="""[DOM] [letter]
+
+Sends a Linux sysrq to a domain.
+""")
+
+gopts.opt('help', short='h',
+ fn=set_true, default=0,
+ use="Print this help.")
+
+def sysrq(dom, req):
+ server.xend_domain_shutdown(dom, 'sysrq', req)
+
+def main(argv):
+ opts = gopts
+ args = opts.parse(argv)
+ if opts.vals.help:
+ opts.usage()
+ return
+
+ # no options for the moment
+ if len(args) < 1: opts.err('Missing domain')
+ if len(args) < 2: opts.err('Missing sysrq character')
+ dom = args[0]
+ req = ord(args[1][0])
+ sysrq(dom, req)